{extend name="base"}
{block name="pageBody"}

<section class="content-wrapper">
	<div class="content-container container">
		<div class="main">
			<h1 class="page-title">忘记密码?</h1>
			<div class="fieldset">
	            <div id="checkUser">
	            	<h2 id="form_head" class="legend">账户信息</h2>
		            <form id="check">
					<ul class="form-list">
						<li class="fields">
							<div class="customer-name">
								<div class="input-box">
									<label>邮箱地址<em>*</em></label>
									<input type="email" class="required-entry input-text" name="user_email">
								</div>
								<div class="input-box">
									<label>手机号<em>*</em></label>
									<input type="text" class="required-entry input-text" name="user_phone">
								</div>
								<div class="clear"></div>
							</div>
		                </li>		
					</ul>
					</form>
					<div class="buttons-set">
						<p class="required">* 为必填项</p>
						<a href="login.html" title="Back" class="f-left">&laquo; 返回登录</a>
						<a style="background-color: #B80000" class="colors-btn" onclick="checkUser()">验证</a>
						<div class="clear"></div>
					</div>
	            </div>
				<div id="reSetPass" style="display: none">
					<h2 class="legend">新密码</h2>
					<form id="rePass">
					<ul class="form-list">
						<input type="hidden" name="user_id">
						<li class="fields">
							<div class="customer-name">
								<div class="input-box name-firstname">
									<label>密码<em>*</em></label>
									<input type="password" class="required-entry input-text" name="user_password">
								</div>
								<div class="input-box name-lastname">
									<label>重复密码<em>*</em></label>
									<input type="password" class="required-entry input-text" id="re">
								</div>
								<div class="clear"></div>
							</div>
						</li>
					</ul>
					</form>
					<div class="buttons-set">
						<p class="required">* 为必填项</p>
						<a href="login.html" title="Back" class="f-left">&laquo; 返回登录</a>
						<a style="background-color: #B80000" class="colors-btn" onclick="resetPass()">修改</a>
						<div class="clear"></div>
					</div>
				</div>
        </div>
		</div>
		<div class="clearfix"></div>
		<div class="news-letter-container">
			<div class="free-shipping-block">
				<h1>ENJOY FREE SHIPPING</h1>
				<p>on all orders as our holiday gift for you!</p>
			</div>
		</div>	
	</div>
</section>

<script>
	function checkUser(){
	  var form = new FormData(document.getElementById("check"));
	  $.ajax({
	      url:"{:url('userdo/checkUser')}",
	      type:"post",
	      data:form,
	      processData: false,                // jQuery不要去处理发送的数据
	      contentType: false,
	      dataType: 'json',
	            success:function(data){
	                if (0 == data.code){
	                	$("#checkUser").css("display","none");
	                	$("#reSetPass").css("display","block");
	                	$("#rePass input[name='user_id']").val(data.data.user_id);
	                }else{
	                  	alert(data.msg);
	                }
	            }
	        });
	  }

	function resetPass(){
	  var password = $("#rePass input[name='user_password']").val();
	  var repassword = $("#re").val();
	  if(password != repassword){
	  	alert("两次密码不同！");
	  	$("#rePass input[name='user_password']").val("");
	    $("#re").val("");
	    $("#rePass input[name='user_password']").focus();

	  	return false;
	  }else{
	      var form = new FormData(document.getElementById("rePass"));
	      $.ajax({
	          url:"{:url('userdo/resetPass')}",
	          type:"post",
	          data:form,
	          processData: false,                // jQuery不要去处理发送的数据
	          contentType: false,
	          dataType: 'json',
	                success:function(data){
	                    if (0 == data.code){
	                    	window.location.href="login";
	                    }else{
	                      	alert(data.msg);
	                    }
	                }
	            });
	      } 
    }
</script>
{/block}